<% title "#{@repository.full_name} - Libraries.io" %>
<% description @repository.description_with_language %>
<%= content_for :meta, render_meta(@repository) %>
<% repo = @repository %>

<% if !repo.private? && repo.is_removed? %>
<div class="alert alert-danger" role="alert">
  <%= fa_icon 'exclamation-triangle' %>
  This repository has been removed and cannot be used anymore.
</div>
<% elsif !repo.private? && repo.is_deprecated? %>
<div class="alert alert-danger" role="alert">
  <%= fa_icon 'exclamation-triangle' %>
  This repository has been marked as deprecated and is not recommended for use anymore.
</div>
<% elsif !repo.private? && repo.is_unmaintained? %>
<div class="alert alert-danger" role="alert">
  <%= fa_icon 'exclamation-triangle' %>
  This repository has been marked as unmaintained and is no longer being updated.
</div>
<% end %>

<div class="row">
  <div class='col-md-8'>
    <h1>
      <% if repo.avatar_url(100).present? %>
        <% if repo.owner.to_s.present? %>
          <%= link_to image_tag(repo.avatar_url(100), width: 50, height: 50, alt: nil), user_path({host_type: repo.host_type.downcase, login: repo.owner_name}) %>
        <% else %>
          <%= image_tag(repo.avatar_url(100), width: 50, height: 50) %>
        <% end %>
      <% end %>
      <%= repo %>
      <%= link_to fa_icon(repo.host_type.downcase), repo.url, class: 'tip', title: "View #{repo} on #{repo.formatted_host}" %>
      <%= fa_icon("lock", title: 'This repo is private', class: 'tip') if repo.private? %>
      <% if repo.fork? %>
        <% if repo.source.present? || repo.source_name.present? %>
          <%= link_to fa_icon('code-fork'), source_path(repo), class: 'tip', title: "Forked from #{repo.source_name}" %>
        <% else %>
          <%= fa_icon("code-fork", title: 'This repo is a fork', class: 'tip') %>
        <% end %>
      <% end %>
    </h1>
    <% if repo.fork? %>
      <small>
        Forked
        <% if repo.source.present? || repo.source_name.present? %>
          from
          <%= link_to repo.source_name, source_path(repo) %>
        <% end %>
      </small>
    <% end %>
  </div>
  <div class="col-md-4">

    <% if current_user && current_user.can_monitor?(repo) %>
      <br>
        <br>
      <% if sub = current_user.subscribed_to_repo?(repo) %>
        <div class="btn-group pull-right">
          <%= link_to unwatch_path(repo.id), method: :post, class: 'tip btn btn-success', title: 'Stop watching' do %>
            <%= fa_icon('check') %>
            Monitoring
          <% end %>
          <%= link_to fa_icon('cog'), edit_repository_subscription_path(sub), class: 'btn btn-success' %>
        </div>
      <% else %>
        <%= button_to watch_path(repo.id), method: :post, class: 'btn btn-primary btn-default  pull-right tip', title: 'Automatically watch every dependency of this project' do %>
          <%= fa_icon('eye') %>
          Monitor dependencies
        <% end %>
      <% end %>
      <%= link_to repository_web_hooks_path(repo.to_param), class: 'btn btn-info pull-right', id: 'webhooks' do %>
        <%= fa_icon 'plug' %>
        Web Hooks
      <% end %>
    <% end %>
    <% if logged_in? && current_user.admin? %>
      <%= link_to 'Admin', admin_repository_path(repo.id), class: 'btn btn-primary pull-right', rel: 'nofollow' %>
    <% end %>
  </div>
</div>
<hr>
<div class='row'>
    <div class='col-md-8'>
      <p>
        <%= emojify repo.description %>
      </p>
      <% if repo.homepage.present? %>
        <p>
          <%= link_to repo.homepage, sanitize_url(repo.homepage), :rel => 'nofollow' %>
        </p>
      <% end %>
      <% if repo.license.present? %>
        <p>
          License: <%= link_to format_license(repo.license), license_path(repo.license) %>
        </p>
      <% end %>
      <% if repo.language.present? %>
      <p>
        Language: <%= link_to repo.language, language_path(repo.language) %>
      </p>
      <% end %>
      <% if repo.keywords.any? %>
      <p>
        Keywords: <%= linked_repo_keywords repo.keywords %>
      </p>
      <% end %>
      <% if repo.mirror_url.present? %>
      <p>
        Mirror of <%= repo.mirror_url %>
      </p>
      <% end %>
      <% if repo.readme.present? %>
        <hr>
        <%== repo.readme %>
      <% end %>

      <div id='repository_dependencies' style='display:none;' data-url="<%= repository_dependencies_path(repo.to_param) %>"></div>
    </div>

  <div class='col-md-4'>
      <h4>Project Statistics</h4>
      <%= render 'repositories/stats', repo: repo %>

      <% if @contributors.length > 0 %>
        <h4>Top Contributors <small><%= link_to 'See all', repository_contributors_path(@repository.to_param) %></small></h4>
        <%= render @contributors %>
      <% end %>

      <% if @projects.length > 0 %>
        <div class="row"></div>
        <hr>
        <h4>Packages Referencing this Repo</h4>
        <%= render @projects, cache: true %>
      <% end %>

      <%= render 'tags', repo: repo %>

      <% if @forks.length > 0 %>
        <div class="row"></div>
        <hr>
        <h4>
          Interesting Forks
          <small><%= link_to 'See all', repository_forks_path(@repository.to_param) %></small>
        </h4>
        <%= render @forks, cache: true %>
      <% end %>

    <div class="row"></div>
    <br>
    <p>
      <%= fa_icon 'question-circle' %>
      Something wrong with this page?
      <%= link_to 'Make a suggestion', 'https://github.com/librariesio/libraries.io/issues/new' %>
    </p>
    <% if repo.last_synced_at.present? %>
      <p>
        <small class='text-muted'>Last synced: <%= repo.last_synced_at %></small>
      </p>
    <% end %>
    <% unless repo.recently_synced? %>
      <% if logged_in? %>
        <p>
          <%= link_to sync_repository_path(repo.to_param), class: 'btn btn-primary btn-xs', method: :post do %>
            <%= fa_icon 'refresh' %>
            Resync Repository
          <% end %>
        </p>
      <% else %>
        <p>
          <small class='text-muted'>
            <%= link_to 'Login', login_path %> to resync this repository
          </small>
        </p>
      <% end %>
    <% end %>
  </div>
</div>
